package com.cmii.sjw.department.control.jsc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cmii.sjw.department.control.jsc.mapper.DistrictKpiMapper;
import com.cmii.sjw.department.control.jsc.model.DistrictKpi;
import com.cmii.sjw.department.control.jsc.service.DistrictKpiService;
import com.cmii.sjw.department.control.jsc.vo.DistrictVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Slf4j
@Service("DistrictKpiService")
public class DistrictKpiServiceImpl extends ServiceImpl<DistrictKpiMapper, DistrictKpi> implements DistrictKpiService {
    @Autowired
    private DistrictKpiMapper districtKpiMapper;

    @Override
    public DistrictVO getKpiByDistrict(String districtName) {
        DistrictKpi entity = districtKpiMapper.selectOne(
                new LambdaQueryWrapper<DistrictKpi>()
                        .eq(DistrictKpi::getDistrict, districtName)
                        .eq(DistrictKpi::getIsDeleted, 0)
                        .last("LIMIT 1")
        );

        if (entity == null) {
            return null;
        }

        DistrictVO vo = new DistrictVO();
        vo.setSchoolSizePercent(entity.getSchoolSizePercent());
        vo.setClassSizePercent(entity.getClassSizePercent());
        return vo;
    }

}
